//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.highglass.videoplayer.subTitle.autodetect;

import java.io.BufferedInputStream;
import java.io.IOException;

public class AutoDetectUtil {
    static String result = null;

    public AutoDetectUtil() {
    }

    public static String detectEncode(int maybeLanguage, BufferedInputStream imp) {
        result = null;
        nsICharsetDetectionObserver cdo = new nsICharsetDetectionObserver() {
            public void Notify(String charset) {
                HtmlCharsetDetector.found = true;
                AutoDetectUtil.result = charset;
            }
        };
        nsDetector det = new nsDetector(maybeLanguage);
        det.Init(cdo);
        byte[] buf = new byte[1024];
        boolean done = false;
        boolean len = true;
        boolean isAscii = true;
        boolean found = false;
        boolean readcount = false;

        int len1;
        try {
            while((len1 = imp.read(buf, 0, buf.length)) != -1) {
                if(isAscii) {
                    isAscii = det.isAscii(buf, len1);
                }

                if(!isAscii && !done) {
                    done = det.DoIt(buf, len1, false);
                }
            }
        } catch (IOException var11) {
            var11.printStackTrace();
        }

        det.DataEnd();
        if(HtmlCharsetDetector.found && result != null) {
            return result;
        } else if(isAscii) {
            found = true;
            return "ascii";
        } else if(!found) {
            String[] prob = det.getProbableCharsets();
            return prob[0];
        } else {
            return null;
        }
    }
}
